#include <linux/init.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/slab.h>

#define PTR(a, b)                                                        \
	pr_info("%-15s=%10d %10ld %8ld\n", a, b, (PAGE_SIZE * b) / 1024, \
		(PAGE_SIZE * b) / 1024 / 1024)

static int __init my_init(void)
{
	struct page *p;
	int i;
	unsigned long pfn, valid = 0;
	int free = 0, locked = 0, reserved = 0, swapcache = 0, referenced = 0,
	    slab = 0, private = 0, uptodate = 0, dirty = 0, active = 0,
	    writeback = 0, mappedtodisk = 0;
	unsigned long num_physpages;

	num_physpages = get_num_physpages();
	for (i = 0; i < num_physpages; i++) {
		pfn = i + ARCH_PFN_OFFSET;
		if (!pfn_valid(pfn))
			continue;

		valid++;
		p = pfn_to_page(pfn);
		if (!page_count(p)) {
			free++;
			continue;
		}

		if (PageLocked(p))
			locked++;
		if (PageReserved(p))
			reserved++;
	}

	pr_info("Examining %ld pages\r\n", num_physpages);

	return 0;
}

static void __exit my_exit(void)
{
	pr_info("Module exit\r\n");
}

module_init(my_init);
module_exit(my_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Module named phypfn.");
